﻿using KendoMvcUI.Core;
using KendoMvcUI.UI.Grid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using KendoMvcUI.Common;

namespace KendoMvcUI.UI
{
    public class JqGrid:MVCUIBase
    {
        public JqGrid(GridSettings settings,ViewContext context,IViewDataContainer viewDataContainer)
            :base(settings,context,viewDataContainer)
        { 
            
        }
        public override string RenderJavascript()
        {
            var script=base.RenderJavascript();
            string jquery = "<script>$(function(){$('#"+Settings.Id+"').jqGrid("+script+")});</script>";
            return jquery + RenderHtml();
        }
        /// <summary>
        /// Html
        /// </summary>
        /// <returns></returns>
        private string RenderHtml()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<table id=\"{0}\"></table>".Formator(Settings.Id));
            var gridSettings = (GridSettings)Settings;
            if (!(gridSettings.Pager.IsNullOrWhiteSpace()))
                sb.AppendLine("<div id=\"{0}\"></div>".Formator(gridSettings.Pager));

            return sb.ToString();
        }
    }
}
